using System;
using System.Drawing;
using System.Windows.Forms;
using Mistral.SecureDrive.DDL;

namespace Mistral.SecureDrive
{
	public class CommonGUI
	{
		ListView _listView_Contents;

		public CommonGUI( ListView listView_Contents )
		{
			_listView_Contents = listView_Contents;
			_listView_Contents.SelectedIndexChanged += ListView_Contents_SelectedIndexChanged;
		}

		public void ListView_Contents_SelectedIndexChanged( object sender, EventArgs e )
		{
			SecureDriveApp.Instance.CurrentContent = GetSelectedContent( _listView_Contents );
		}
		
		public static Content GetSelectedContent( ListView listView )
		{
			Content selectedContent = null;
			if( listView.SelectedItems.Count == 1 )
			{
				selectedContent = (Content)listView.SelectedItems[0].Tag;
			}
			return selectedContent;
		}

		public static Image GetWorkFolderStatusImage()
		{
			Image image = null;
			if( SecureDriveApp.Instance.WorkFolder.State == FolderState.Off )
			{
				image = Resource16.ball_red;
			}
			if( SecureDriveApp.Instance.WorkFolder.State == FolderState.Ready_Empty )
			{
				image = Resource16.ball_yellow;
			}
			if( SecureDriveApp.Instance.WorkFolder.State == FolderState.Ready_HasData )
			{
				image = Resource16.ball_green;
			}
			return image;
		}
	}
}